<script type="text/javascript">
	$(document).ready(function(){
		$("#status").change(function(){
			var status = $("#status").val();
			if (status == "Perpanjang"){
				$('#kode_lama').show('slow');
			}else if(status == "Baru"){
				$('#kode_lama').hide('slow');
			}
		});
	});
</script>

<script type="text/javascript">
function hapusPerawatan(obj){	
	 if (confirm('Apakah data akan dihapus ?')) {
  		obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
	}
}
function add_data() {
        var tampil_tombol_aksi = '<a href="javascript:void(null)" title="Hapus" onclick="hapusPerawatan(this)"><img src="asset/images/button-delete.gif" alt="Hapus" border=0 /></a>';
  		var tr = document.createElement('tr');
  		var td_ruang = document.createElement('td');
		var td_tglmasuk = document.createElement('td');
		var td_tglkeluar = document.createElement('td');
  		var td_aksi = document.createElement('td');  		
  		var tbodi = document.getElementById("tbody_list_ruang");
  		
  		td_aksi.className = 'links';
  		td_aksi.width = 15;
  		td_ruang.innerHTML = "<select name='ruang2[]'>"+"<?php $ruang = mysql_query("select * from ruang"); 
		while($r = mysql_fetch_array($ruang)){ 
		$str_ruang.= "<option value=$r[id_ruang]>$r[ruang]</option>";
		} 
		echo $str_ruang;
		?>"+"</select>";
		td_tglmasuk.innerHTML = '<input type="text" name="tgl_masuk[]" class="tgl_rawat" size="10">';
		td_tglkeluar.innerHTML = '<input type="text" name="tgl_keluar[]" class="tgl_rawat" size="10">';

  		td_aksi.innerHTML = tampil_tombol_aksi;
  		
  		tr.appendChild(td_ruang);
		tr.appendChild(td_tglmasuk);
		tr.appendChild(td_tglkeluar);

  		tr.appendChild(td_aksi);
  		tbodi.appendChild(tr);
		
}
  
	$(document).ready(function(){
		$(".tgl_rawat").datepicker();
		$('#show').hide();
		$('#kunjungan').change(function(){
			if(this.checked)
				$('#show').hide('slow');
			else
				$('#show').show('slow');

		});
	});

	$(function() {
		$( "#datepicker1" ).datepicker();
	});
  
	$(function() {
		$( "#datepicker2" ).datepicker();
		
	});
</script>
<div id="tiga_ba">
	<div id="tiga_baa">Ubah Data Jaminan</div>
	<div id="tiga_bab"></div>
	<div class="clear"></div>
</div>
<?php
	$id = $_GET['id'];
	$cek = mysql_num_rows(mysql_query("select j.id_jaminan from jaminan j inner join jaminan_ritl jr on j.id_jaminan = jr.id_jaminan where j.id_jaminan = '$id'"));
	if($cek > 0){
		$hasil = mysql_fetch_array(mysql_query("select * from jaminan j inner join peserta p on j.id_peserta = p.id_peserta inner join penduduk pn on p.id_penduduk = pn.id_penduduk inner join jaminan_ritl jr on j.id_jaminan = jr.id_jaminan where j.id_jaminan = '$id'"));
		?>
		<form action="utama.php?module=mod_jaminan&act=update" onsubmit="return gsValidate('id_jaminan|status|catatan|jenis','ID Jaminan Harus Diisi|Status Harus Diisi|Catatan Kunjungan Harus Diisi|Jenis Kunjungan Harus Diisi','required|required|required|required');" method="post" enctype="multipart/form-data">
			<table border=0>
				<tr>
					<td valign="top">
						<table style="margin: 10px 15px 0px 15px;">
							<tr>
					<td width="150">ID Jaminan</td>
					<td width="300">
						<input name="id_oto" type="text" id="id_oto" class="input2" value="<?php echo $hasil['id_jaminan']; ?>" disabled/>
						<input name="id_jaminan" type="hidden" id="id_jaminan" class="input2" value="<?php echo $hasil['id_jaminan']; ?>"/>
					</td>
				</tr>
				<tr>
					<td>ID Peserta</td>
					<td>
						<input name="id_peserta" type="text" id="id_peserta" value="<?php echo $hasil['id_peserta']; ?>" class="input2" disabled/>
						<input name="id" type="hidden" id="id" value="<?php echo $hasil['id_peserta']; ?>" class="input2"/>
					</td>
				</tr>
				<tr>
					<td>Nama</td>
					<td>
						<input name="nama" type="text" id="nama" value="<?php echo $hasil['nama']; ?>" class="input2" disabled/>
					</td>
				</tr>
				<tr>
					<td>Tempat, Tanggal Lahir</td>
					<td>
						<input name="ttl" type="text" id="ttl" value="<?php echo $hasil['tempat_lahir'].", ".tgl_ind1($hasil['tgl_lahir']); ?>" class="input2" disabled/>
					</td>
				</tr>
				<tr>
					<td>Status</td>
					<td>
						<select name="status" id="status" class="input2" disabled>
							<?php
								if($hasil['status'] == 'Baru'){
									$sb = "selected";
									$sp = "";
								}else{
									$sb = "";
									$sp = "selected";
								}
							?>
							<option value=""> - - Pilih Status - - </option>
							<option value="Baru" <?php echo $sb; ?>>Baru</option>
							<option value="Perpanjang" <?php echo $sp; ?>>Perpanjang</option>
						</select>
					</td>
				</tr>
			</table>
			<?php
				if($hasil['status'] == 'Perpanjang'){
			?>
				<div id="kode_lama">
					<table style="margin: 0px 15px 0px 15px;">
						<tr>
							<td width="98">ID Jaminan Sebelumnya</td>
							<td width="250">
								<input name="id_lama2" type="text" id="id_lama" class="input2" value="<?php echo $hasil['id_jaminan_sebelumnya'] ?>" disabled/>
								<input name="id_lama" type="hidden" id="id_lama" class="input2" value="<?php echo $hasil['id_jaminan_sebelumnya'] ?>"/>
							</td>
						</tr>
					</table>
				</div>
			<?php
				}
			?>
			<table style="margin: 0px 15px 0px 15px;">
				<tr>
					<td width="150">Tanggal Mulai</td>
					<td width="300">
						<input name="tgl_mulai" type="text" id="datepicker1" value="<?php echo tgl_ind3($hasil['tgl_mulai']);?>" class="input2"/>
					</td>
				</tr>
				<tr>
					<td>Tanggal Selesai</td>
					<td>
						<input name="tgl_selesai" type="text" id="datepicker2" value="<?php echo tgl_ind3($hasil['tgl_selesai']);?>" class="input2"/>
					</td>
				</tr>
				<tr>
					<td width="150">Catatan Kunjungan</td>
					<td width="300">
						<select name="catatan" id="catatan" class="input2">
							<option value=""> - - Pilih Catatan Kunjungan - - </option>
							<?php
								$query = mysql_query("select * from catatan_kunjungan");
								while($data = mysql_fetch_array($query)){
									if($data['id_catatan_kunjungan'] == $hasil['id_catatan_kunjungan']){
										$s = "selected";
									}else{
										$s = "";
									}
									echo "<option value='$data[id_catatan]' $s>$data[catatan_kunjungan]</option>";
								}
							?>
						</select>
					</td>
				</tr>
			</table>
					</td>
					<td valign="top">
						<table style="margin: 10px 15px 0px 0px;">
							<tr>
								<td width="130">Nomer MR</td>
								<td width="310">
									<input name="mr" type="text" id="mr" class="input2" value="<?php echo $hasil['no_mr']; ?>"/>
								</td>
							</tr>
							<tr>
								<td>Hak Kelas Perawatan</td>
								<td>
									<select name="kelas" id="kelas" class="input2"/>
										<?php
											$kelas = mysql_query("select * from kelas_perawatan");
											while($k = mysql_fetch_array($kelas)){
												if($k['id_kelas_perawatan'] == $hasil['id_kelas_perawatan']){
													$s = "selected";
												}else{
													$s = "";
												}
												echo "<option value=$k[id_kelas_perawatan] $s>$k[kelas_perawatan]</option>";
											}
										?>
									</select>
								</td>
							</tr>
							<tr>
								<td>Ruang Perawatan</td>
								<td>
									<select name="ruang" id="ruang" class="input2"/>
										<?php
											$ruang = mysql_query("select * from ruang");
											while($r = mysql_fetch_array($ruang)){
												if($r['id_ruang'] == $hasil['id_ruang_perawatan']){
													$s = "selected";
												}else{
													$s = "";
												}
												echo "<option value=$r[id_ruang] $s>$r[ruang]</option>";
											}
										?>
									</select>
								</td>
							</tr>
							<tr>
								<td>Perawatan : </td>
								<td align="right">
									<a href="javascript:add_data()" onclick=""><img src="asset/images/add.png"></a>
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<table class="tabel2" width="100%">
										<tr>
											<th>Ruang Perawatan</th>
											<th>Tanggal Masuk</th>
											<th>Tanggal Keluar</th>
											<th></th>
										</tr>
										<tbody id="tbody_list_ruang">
										</tbody>
										
									</table>
								</td>
							</tr>
							<tr>
								<td></td>
								<td align="right"></td>
							</tr>
							<tr>
								<td>Diagnosa Awal</td>
								<td>
									<input name="diagnosa_awal" type="text" id="diagnosa_awal" class="input3" value="<?php echo $hasil['diagnosa_awal']; ?>"/>
								</td>
							</tr>
							<tr>
								<td>Diagnosa Keluar</td>
								<td>
									<input name="diagnosa_keluar" type="text" id="diagnosa_keluar" class="input3" value="<?php echo $hasil['diagnosa_keluar']; ?>"/>
								</td>
							</tr>
							<tr>
								<td>Catatan Khusus</td>
								<td>
									<input name="catatan2" type="text" id="catatan" class="input3" value="<?php echo $hasil['catatan_khusus']; ?>"/>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table style="margin: 10px 15px 0px 15px;">
							<tr>
								<td width="140"></td>
								<td width="250">
									<input name="submit" type="submit" class="button" value="Simpan" />
								</td>
							</tr>
						</table>
					</td>
					<td></td>
				</tr>
			</table>
		</form>
		<?php
	}else{
		$hasil = mysql_fetch_array(mysql_query("select * from jaminan j inner join peserta p on j.id_peserta = p.id_peserta inner join penduduk pn on p.id_penduduk = pn.id_penduduk where id_jaminan = '$id'"));
	?>
		<form action="utama.php?module=mod_jaminan&act=update" onsubmit="return gsValidate('id_jaminan|status|catatan|jenis','ID Jaminan Harus Diisi|Status Harus Diisi|Catatan Kunjungan Harus Diisi|Jenis Kunjungan Harus Diisi','required|required|required|required');" method="post" enctype="multipart/form-data">
			<table style="margin: 10px 15px 0px 15px;">
				<tr>
					<td width="150">ID Jaminan</td>
					<td width="300">
						<input name="id_oto" type="text" id="id_oto" class="input2" value="<?php echo $hasil['id_jaminan']; ?>" disabled/>
						<input name="id_jaminan" type="hidden" id="id_jaminan" class="input2" value="<?php echo $hasil['id_jaminan']; ?>"/>
					</td>
				</tr>
				<tr>
					<td>ID Peserta</td>
					<td>
						<input name="id_peserta" type="text" id="id_peserta" value="<?php echo $hasil['id_peserta']; ?>" class="input2" disabled/>
						<input name="id" type="hidden" id="id" value="<?php echo $hasil['id_peserta']; ?>" class="input2"/>
					</td>
				</tr>
				<tr>
					<td>Nama</td>
					<td>
						<input name="nama" type="text" id="nama" value="<?php echo $hasil['nama']; ?>" class="input2" disabled/>
					</td>
				</tr>
				<tr>
					<td>Tempat, Tanggal Lahir</td>
					<td>
						<input name="ttl" type="text" id="ttl" value="<?php echo $hasil['tempat_lahir'].", ".tgl_ind1($hasil['tgl_lahir']); ?>" class="input2" disabled/>
					</td>
				</tr>
				<tr>
					<td>Status</td>
					<td>
						<select name="status" id="status" class="input2" disabled>
							<?php
								if($hasil['status'] == 'Baru'){
									$sb = "selected=selected";
									$sp = "";
								}else{
									$sb = "";
									$sp = "selected=selected";
								}
							?>
							<option value=""> - - Pilih Status - - </option>
							<option value="Baru" <?php echo $sb; ?>>Baru</option>
							<option value="Perpanjang" <?php echo $sp; ?>>Perpanjang</option>
						</select>
					</td>
				</tr>
			</table>
			<?php
				if($hasil['status'] == 'Perpanjang'){
			?>
				<div id="kode_lama">
					<table style="margin: 0px 15px 0px 15px;">
						<tr>
							<td width="150">ID Jaminan Sebelumnya</td>
							<td width="250">
								<input name="id_lama2" type="text" id="id_lama" class="input2" value="<?php echo $hasil['id_jaminan_sebelumnya'] ?>" disabled/>
								<input name="id_lama" type="hidden" id="id_lama" class="input2" value="<?php echo $hasil['id_jaminan_sebelumnya'] ?>"/>
							</td>
						</tr>
					</table>
				</div>
			<?php
				}
			?>
			<table style="margin: 0px 15px 0px 15px;">
				<tr>
					<td width="150">Tanggal Mulai</td>
					<td width="300">
						<input name="tgl_mulai" type="text" id="datepicker1" value="<?php echo tgl_ind3($hasil['tgl_mulai']);?>" class="input2"/>
					</td>
				</tr>
				<tr>
					<td>Tanggal Selesai</td>
					<td>
						<input name="tgl_selesai" type="text" id="datepicker2" value="<?php echo tgl_ind3($hasil['tgl_selesai']);?>" class="input2"/>
					</td>
				</tr>
				<tr>
					<td width="150">Catatan Kunjungan</td>
					<td width="300">
						<select name="catatan" id="catatan" class="input2">
							<option value=""> - - Pilih Catatan Kunjungan - - </option>
							<?php
								$query = mysql_query("select * from catatan_kunjungan");
								while($data = mysql_fetch_array($query)){
									if($data['id_catatan_kunjungan'] == $hasil['id_catatan_kunjungan']){
										$s = "selected='selected'";
									}else{
										$s = "";
									}
									echo "<option value='$data[id_catatan_kunjungan]' $s>$data[catatan_kunjungan]</option>";
								}
							?>
						</select>
					</td>
				</tr>
				<tr>
					<td>Jenis Kunjungan</td>
					<td>
						<select name="jenis" id="jenis" class="input2">
							<option value=""> - - Pilih Jenis Kunjungan - - </option>
							<?php
								$query = mysql_query("select * from jenis_kunjungan where id_jenis_kunjungan <> 4");
								while($data = mysql_fetch_array($query)){
									if($data['id_jenis_kunjungan'] == $hasil['id_jenis_kunjungan']){
										$s = "selected";
									}else{
										$s = "";
									}
									echo "<option value='$data[id_jenis_kunjungan]' $s>$data[jenis_kunjungan]</option>";
								}
							?>
						</select>
					</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td><input name="submit" type="submit" class="button" value="Simpan" /></td>
				</tr>
			</table>                
		</form>
	<?php
	}
?>
            
        